﻿using Models;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Scheduledscheduling
{
    public partial class Form1 : Form
    {      
        public Form1()
        {
            InitializeComponent();
            this.Text = "【调度管理】";
            this.StartPosition = FormStartPosition.CenterScreen;
            this.ControlBox = true;

            this.MaximizeBox = false;
            //this.AcceptButton.
            this.FormClosing += new FormClosingEventHandler(Frm_Closing);
        }

        private void Frm_Closing(object sender, FormClosingEventArgs e)
        {
            DialogResult result = MessageBox.Show("确认退出应用程序吗？", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

            if (result == DialogResult.No)
            {
                e.Cancel = true; // 取消窗体关闭操作
            }
            else
            {
                System.Environment.Exit(0);
            }
        }




        private void button1_Click(object sender, EventArgs e)
        {
         
            Login();
            // Sugar.db.DbFirst.StringNullable().CreateClassFile($@"D:\wrok\调度模块\Scheduledscheduling\Scheduledscheduling\Models\"); 
        }

        private void Login()
        {
            var token = textBox1.Text.Trim();
            var tokenDb = Sugar.db.Queryable<User>().Where(it => it.UserToken == token).ToList().FirstOrDefault();
            if (tokenDb != null)
            {
                Main frm = new Main(tokenDb);

                frm.Show();
                this.Hide();
            }
        }

        private void textBox1_Click(object sender, EventArgs e)
        {
            textBox1.Text = null;
        }


        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                Login();
            }
        }
    }
}
